/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Form = require("form");
	var enmu = require("enums");
	var Dialog = require("dialog");
	
	
    var instance = {
        renderForm: function (widget,addButton) {
        	var defaultItems = [];
        	defaultItems = [{
				name : "memberCertificates",
				label : "会员证号",
				validate : [ "required" ],
				events:{
					"blur":function(e){
						var memberCertificates = e.target.value;
						if(memberCertificates){
							widget.handler.form.searchContact(widget,memberCertificates);
						}
					}
				}
			},{
				name: "contactNo",
				label:"合同号",
				readonly:true
			},{
				name: "balance",
				label: "余额",
				readonly:true
			},{
				name: "balTime",
				label: "居住期限余额",
				readonly:true
			},{
				name:"unit",
				label:"期限单位",
				options: enmu["com.eling.elcms.travel.model.ProductRuleDetail.Unit"],
				readonly:true
			},{
				name: "personalInfo.name",
				label: "持证人",
				readonly:true
			}];
        	if(!addButton){
        		defaultItems.push({
			            name: "personalInfo.sex",
			            label:"性别",
			            type: "radio",
			            validate: ["required"],
			            defaultValue : "Male",
						list : enmu["com.eling.elcms.basedoc.model.Sex"],
					})
        	}
        	defaultItems.push({
				name: "personalInfo.idNumber",
				label: "身份证号",
				readonly:true
			},{
				name: "personalInfo.phone",
				label: "联系电话",
				readonly:true
			},{
				name: "productRule",
				label: "产品",
				readonly:true
			},{
				name: "productType",
				label: "产品类型",
				readonly:true
			},{
				name: "signUpDate",
				label: "签约日期",
				type: "date",
				mode:"YYYY-MM-DD",
				readonly:true
			});
        	if(addButton){
        		defaultItems.push({
    				name: "startDate",
					label: "开始日期",
					type: "date",
					mode:"YYYY-MM-DD",
					readonly:true
    			},{
    				name: "endDate",
					label: "终止日期",
					type: "date",
					mode:"YYYY-MM-DD",
					readonly:true
    			})
        	};
        	defaultItems.push({
				name: "status.value",
				label: "状态",
				readonly:true
			});
        	if(addButton){
        		defaultItems.push({
    				name: "transferType",
    				label: "转让类型",
    				type:"select",
    				validate : [ "required" ],
    				options:enmu["com.eling.elcms.travel.model.CertificatesTransfer.TransferType"]
    			})
        	}else{
        		defaultItems.push({
    				name: "transferType",
    				label: "转让类型"
    			})
        	}
        	if(addButton){
        		defaultItems.push({
    				name: "workCost",
					label: "工本费（元）",
					validate : [ "required" ],
					events : {
                       	 "change" : function(e){
                       		 var workCost = form.getValue("workCost");
                       		 if(!isNaN(workCost) && parseInt(workCost) > 0){
                       			form.setValue("workCost", parseFloat(workCost).toFixed(2));
                       		 } else{
                       			 Dialog.alert({
                       				 tip : "提示",
                       				 content : "工本费必须输入数字且不能为负！"
                       			 });
                       			 form.setValue("workCost", "");
                       			 return false;
                       		 }
                       	 }
                    }
    			})
        	};
        	defaultItems.push({
				name:"pkTravelContract",
				type:"hidden"
			},{
				name:"version",
				type:"hidden"
			},{
				name:"personalInfo.pkPersonalInfo",
				type:"hidden"
			});
        	var form = new Form({
        		parentNode: ".J-form",
        		model: {
        			id: "form",
        			layout: "3_1",
        			defaultButton : false,
        			items: defaultItems
        		}
        	});
        	$(".J-form").find(".box-content").before($("<div></div>").addClass("box-header")
        			.append($("<div></div>").addClass("title").text("转让信息")));
        	widget.set("form",form);
        }
    };
    module.exports = instance;
});
